import log from "./logger";
import axios from "axios";

class Settings {
    public id: number
    public code: string
    public host: string
    public name: string;
    public platformId: number
    public platformName: string
    public type: string;
    public configJson: any;

    async getEdgeConfig() {
        log.info('getEdgeConfig()')
        try {
            const response = await axios.get(this.host + '/api/weigh/external/device/detailByCode/' + this.code)
            const d = response.data.data
            log.info("settings:", JSON.stringify(d));
            this.id = d.id;
            this.code = d.code;
            this.name = d.name;
            this.platformId = d.platformId;
            this.platformName = d.platformName;
            this.configJson = d.configJson;
            this.type = d.type;
        } catch (e) {
            throw e;
        }
    }

    async init() {
        this.code = process.argv[2];
        this.host = process.argv[3];
        try {
            await this.getEdgeConfig();
        } catch (e) {
            throw e;
        }
    }
}

const settings = new Settings();

export default settings;